<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
	<meta charset="UTF-8">
	<title>后台登录</title>
	<jsp:include page="/static/commonjsp/head-js.jsp" flush="true"/>
</head>
<body class="login-bg">

    <div class="login layui-anim layui-anim-up">
        <div class="message">json——管理登录</div>
        <div id="darkbannerwrap"></div>
        <form method="post" class="layui-form" id="login-form" >
            <input name="username" placeholder="用户名"  type="text" lay-verify="required" class="layui-input" ><hr class="hr15">
            <input name="password" id="password" lay-verify="required" placeholder="密码"  type="password" class="layui-input"><hr class="hr15">
            <input value="登录" lay-submit lay-filter="login" style="width:100%;" type="submit"><hr class="hr20" >
        </form>
    </div>

<script>
$(function() {
	layui.use(['form','layer'], function() {
		var form = layui.form;
		var layer = layui.layer;
		//监听提交
		form.on('submit(login)', function(data) {
			$.ajax({
				url:"${pageContext.request.contextPath}/login/login",
				type:"POST",
				//keyValue数据格式
				data:$('#login-form').serialize(),
				success: function(res){
					if(res.success==true){
						window.setTimeout("window.location.href='${pageContext.request.contextPath}/login/home' ", 1000);
						layer.msg(res.msg+"，正在跳转..."); 
					}else if(res.success==false){
						layer.msg(res.msg); 
						$("#password").val('');
					}
				},
				error: function(){
					layer.msg("请求服务器失败"); 
				}
			});
			return false;
		});
	});
})
</script>
    
</body>
</html>